package com.yanqu.road.server.cmd.chefduel;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.activity.chefDuel.eChefDuelActivityType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.chefduel.ChefDuelProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.chefduel.ChefDuelActivityMgr;
import com.yanqu.road.server.manger.activity.chefduel.ChefDuelMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_CHEF_DUEL_WORSHIP, desc = "膜拜排行第一名")
public class ChefDuelWorshipCmd extends AbstractCommand {

	int activityId;
	String reward;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		ChefDuelProto.ChefDuelWorshipReqMsg reqMsg = ChefDuelProto.ChefDuelWorshipReqMsg.parseFrom(packet.getBytes());
		activityId = reqMsg.getActivityId();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ActivityInfo activityInfo = ChefDuelActivityMgr.getOpenActivityInfo(activityId);
		if(activityInfo == null){
			ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
			return;
		}
		if(activityInfo.getChildType() == eChefDuelActivityType.Phase1.getChildType()){
			ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
		}else if(activityInfo.getChildType() == eChefDuelActivityType.Phase2.getChildType()){
			ret = ChefDuelMgr.worship2(activityId,player.getUserId());
		}else if(activityInfo.getChildType() == eChefDuelActivityType.Phase3.getChildType()){
			ret = ChefDuelMgr.worship3(activityId,player.getUserId());
		}else{
			ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
		}

	}

	@Override
	public void sendData(GamePlayer player) {
		ChefDuelProto.ChefDuelWorshipRespMsg.Builder respMsg = ChefDuelProto.ChefDuelWorshipRespMsg.newBuilder();
		respMsg.setRet(ret);
		if(ret == 0){
			ActivityInfo activityInfo = ChefDuelActivityMgr.getOpenActivityInfo(activityId);
			if(activityInfo.getChildType() == eChefDuelActivityType.Phase1.getChildType()){
//				respMsg.setReward(ChefDuelActivityMgr.getWorshipReward(activityId));
			}else if(activityInfo.getChildType() == eChefDuelActivityType.Phase2.getChildType()){
				respMsg.setReward(ChefDuelActivityMgr.getWorship2Reward(activityId));
			}else if(activityInfo.getChildType() == eChefDuelActivityType.Phase3.getChildType()){
				respMsg.setReward(ChefDuelActivityMgr.getWorship3Reward(activityId));
			}
		}
		player.sendPacket(Protocol.U_CHEF_DUEL_WORSHIP, respMsg);
	}
}
